//
//  foundQuestTopheaderView.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/7/31.
//

#import "foundQuestTopheaderView.h"
#import "YTBaseSelectStringView.h"

@interface foundQuestTopheaderView ()
@property (nonatomic ,strong)YTBaseSelectStringView * bzview;
@property (nonatomic ,strong)YTBaseSelectStringView * gzview;

@property (nonatomic ,strong)UIView * tkMakeView;
@property (nonatomic ,strong)UILabel * tkmrLab;

@end

@implementation foundQuestTopheaderView

+ (instancetype)NewView {
    foundQuestTopheaderView * view = [foundQuestTopheaderView new];
    view.clipsToBounds = YES;
    [view setupView];
    return view;
}
- (void)setupView{
    MJWeakSelf
    UIView * makeview = [UIView new];
    makeview.backgroundColor = UIColor.whiteColor;
    [self addSubview:makeview];
    [makeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.offset(0);
    }];
    
    YTBaseSelectStringView * bzview = [YTBaseSelectStringView NewView];
    self.bzview = bzview;
    bzview.name = @"池塘编组";
    bzview.forceFlag = YES;
    bzview.block = ^(NSString * _Nonnull content) {
        if(weakSelf.openTKBZBlock){
            weakSelf.openTKBZBlock(weakSelf.model);
        }
    };
    [makeview addSubview:bzview];
    [bzview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(kwt(5));
        make.right.offset(kwt(-10));
        make.left.offset(kwt(10));
        make.height.offset(kwt(60));
    }];
    
    YTBaseSelectStringView * gzview = [YTBaseSelectStringView NewView];
    gzview.name = @"工作模板";
    gzview.block = ^(NSString * _Nonnull content) {
        if(weakSelf.openTKMBBlock){
            weakSelf.openTKMBBlock(weakSelf.model);
        }
    };
    self.gzview = gzview;
    gzview.forceFlag = YES;
    [makeview addSubview:gzview];
    [gzview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-10));
        make.left.offset(kwt(10));
        make.height.offset(kwt(60));
        make.top.equalTo(bzview.mas_bottom);
    }];
    
    
    UIView * tkview = [UIView new];
    tkview.addClickBlock(^{
        if(weakSelf.openTKMCBlock){
            weakSelf.openTKMCBlock(weakSelf.model);
        }
    });
    [DTKTool YJ:kwt(5) andView:tkview];
    tkview.backgroundColor = KcolorHex(@"#F6F7F9");
    [makeview addSubview:tkview];
    [tkview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.right.offset(kwt(-10));
        make.top.equalTo(gzview.mas_bottom).offset(kwt(5));
    }];
    
    UILabel * forceFlagLab = [DTKTool labelWithText:@"*" andFont:kCFont(17) andTextColor:KcolorHex(@"#FA0F0F")];
    [tkview addSubview:forceFlagLab];
    forceFlagLab.mas_KLS().mas_KYS();
    [forceFlagLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.top.offset(kwt(15));
        make.height.offset(kwt(20));
    }];
    
    UILabel * nameLab = [DTKTool labelWithText:@"池塘名称" andFont:kCFont(17) andTextColor:KcolorHex(@"#222222")];
    nameLab.mas_KLS().mas_KYS();
    [tkview addSubview:nameLab];
    [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(forceFlagLab.mas_right);
        make.centerY.equalTo(forceFlagLab);
    }];
    
    UILabel * tkmrLab = [DTKTool labelWithText:@"请选择" andFont:kFont(18) andTextColor:KcolorHex(@"#787A79")];
    self.tkmrLab = tkmrLab;
    [tkview addSubview:tkmrLab];
    [tkmrLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-33));
        make.centerY.equalTo(nameLab);
    }];
    
    
    
    UIImageView * rightimg = kimageView(@"template_enter");
    [tkview addSubview:rightimg];
    [rightimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-10));
        make.centerY.equalTo(forceFlagLab);
        make.width.height.offset(kwt(15));
    }];
    
    UIView * tkMakeView = [UIView new];
    self.tkMakeView = tkMakeView;
    [tkview addSubview:tkMakeView];
    [tkMakeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-10));
        make.left.offset(kwt(10));
        make.top.offset(kwt(40));
        make.bottom.offset(kwt(-10));
    }];
    
    
    
    UIView * addRWView = [UIView new];
    addRWView.addClickBlock(^{
        [weakSelf openRWLXClick];
    });
    addRWView.backgroundColor = KcolorHex(@"#F0F5FF");
    [DTKTool YJ:kwt(5) andView:addRWView];
    [makeview addSubview:addRWView];
    [addRWView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.top.equalTo(tkview.mas_bottom).offset(kwt(10));
        make.right.offset(kwt(-10));
        make.height.offset(kwt(53));
    }];
    
    UILabel * lab = [DTKTool labelWithText:@"+选择任务名称" andFont:kCFont(17) andTextColor:KcolorHex(@"#0967FF")];
    [addRWView addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.offset(0);
    }];
    
}
- (void)openRWLXClick{
    if(self.openRWBlock){
        self.openRWBlock(self.model);
    }
}

-(void)setModel:(foundQuestModel *)model {
    _model = model;
    self.bzview.content = model.tissueName;
    self.gzview.content = model.templateName;
    self.tkmrLab.hidden = (model.pondModelListModel.count != 0);
    [self.tkMakeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(model.HeaderTopPondViewH);
    }];
    [self.tkMakeView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    CGFloat Y = kwt(10);
    for (pondModelListModel * pmodel in model.pondModelListModel) {
        UIView * leftview = [UIView new];
        leftview.backgroundColor = UIColor.whiteColor;
        [DTKTool YJBK:kwt(4) andView:leftview andWidth:kwt(1.5) andColor:KcolorHex(@"#0967FF")];
        [self.tkMakeView addSubview:leftview];
        [leftview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(kwt(2));
            make.top.offset(Y);
            make.width.height.offset(kwt(8));
        }];
        
        UILabel * leftlab = [DTKTool labelWithText:pmodel.name andFont:kFont(18) andTextColor:KcolorHex(@"#222222")];
        [self.tkMakeView addSubview:leftlab];
        [leftlab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(kwt(15));
            make.centerY.equalTo(leftview);
        }];
        Y += kwt(28);
    }
}

@end
